package com.normal.practise.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Siyao, Lee
 * @date 2021-05-09 20:09
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        // 起始版本 3.3.0(推荐)
//        this.strictInsertFill(metaObject, "gmtCreate", LocalDateTime.class, LocalDateTime.now());
//        this.strictInsertFill(metaObject, "gmtUpdate", LocalDateTime.class, LocalDateTime.now());
//
//        Object create = getFieldValByName("gmtCreate", metaObject);
//        log.info("gmtCreate" + create);
        this.setFieldValByName("gmtCreate", new Date(), metaObject);
        this.setFieldValByName("gmtUpdate", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ...." + "   Date()  " + new Date());
        // 起始版本 3.3.0(推荐)
//        this.strictUpdateFill(metaObject, "gmtUpdate", LocalDateTime.class, LocalDateTime.now());
        this.setFieldValByName("gmtUpdate", new Date(), metaObject);
    }
}
